package com.translate.web.api.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.NativeWebRequest;

import com.basic.service.contract.IBaseService;
import com.controller.base.AbstractCommonController;
import com.param.impl.IdParam;
import com.response.vo.ResponseModel;
import com.translate.entity.NoticeCenter;
import com.translate.vo.NoticeCenterVO;
import com.translate.web.param.NoticeCenterAddParam;
import com.translate.web.param.NoticeCenterUpdateParam;
import com.translate.web.param.SearchNoticeParam;
import com.translate.web.param.UserIdParam;
import com.translate.web.service.INoticeCenterService;

@RestController
@RequestMapping("noticeCenter")
public class NoticeCenterController extends AbstractCommonController<NoticeCenter, SearchNoticeParam> {
	
	private INoticeCenterService service;
	
	public NoticeCenterController(INoticeCenterService service) {
        this.service = service;
    }
	
	@Override
	protected void frontProcesserVO(SearchNoticeParam param, NativeWebRequest object) {
		
		param.setSelectCount(100);
		param.setUserId((int) this.getUserId(object));
		
		super.frontProcesserVO(param, object);
	}

	/**
	 * 添加
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/add")
	public ResponseModel<Integer> insert(@RequestBody @Validated NoticeCenterAddParam param,
			HttpServletRequest httpServletRequest) {
		int id = this.service.parseInsert(param, NoticeCenter.class);

		return ResponseModel.<Integer>success(id);
	}

	@Override
	protected IBaseService<NoticeCenter> getBaseService() {
		return this.service;
	}

	
	
	
	/**
	 * 添加
	 * 
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResponseModel<Integer> update(@Validated @RequestBody IdParam param,
			HttpServletRequest httpServletRequest) {
		
		NoticeCenter noticeCenter = new NoticeCenter();
		
		noticeCenter.setId(param.getId());
		
		noticeCenter.setReadStatus((byte) 1);
		
		int res = this.service.updateByPrimaryKeySelective(noticeCenter);
		return ResponseModel.<Integer>success(res);
	}

	protected <VO> Class<VO> getTarget() {
		return (Class<VO>) NoticeCenterVO.class;
	}
}